<template>
  <div class="page-header-index-wide">
    <a-row :gutter="24" style='padding: 0 12px !important; '>
      <a-col :sm="24" :md="12" :xl="4" :style="{padding:0, marginBottom: '24px' }">
        <chart-card :loading="loading" title="预算总金额" total="￥156,5602">
          <a-tooltip title="指标说明" slot="action">
            <a-icon type="info-circle-o" />
          </a-tooltip>
          <template slot="footer" style='text-align: right'>
            <trend flag="up" style="margin-right: 16px;">
                  <span slot="term">周同比</span>
                   12%
            </trend>
          </template>
        </chart-card>
      </a-col>
      <a-col :sm="24" :md="11" :xl="4" :offset='1' :style="{padding:0, marginBottom: '24px' }">
        <chart-card :loading="loading" title="经销商预算总金额" total="￥1342123">
          <a-tooltip title="指标说明" slot="action">
            <a-icon type="info-circle-o" />
          </a-tooltip>
          <template slot="footer" style='text-align: right'>
            <trend flag="up" style="margin-right: 16px;">
              <span slot="term">周同比</span>
              12%
            </trend>
          </template>
        </chart-card>
      </a-col>
      <a-col :sm="24" :md="11" :xl="4" :offset='1' :style="{padding:0, marginBottom: '24px' }">
        <chart-card :loading="loading" title="执行中活动金额" total="￥783243">
          <a-tooltip title="指标说明" slot="action">
            <a-icon type="info-circle-o" />
          </a-tooltip>
          <template slot="footer" style='text-align: right'>
            <trend flag="up" style="margin-right: 16px;">
              <span slot="term">周同比</span>
              12%
            </trend>
          </template>
        </chart-card>
      </a-col>
      <a-col :sm="24" :md="11" :xl="4" :offset='1' :style="{padding:0, marginBottom: '24px' }">
        <chart-card :loading="loading" title="待核销金额" total="￥243094">
          <a-tooltip title="指标说明" slot="action">
            <a-icon type="info-circle-o" />
          </a-tooltip>
          <template slot="footer" style='text-align: right'>
            <trend flag="up" style="margin-right: 16px;">
              <span slot="term">周同比</span>
              12%
            </trend>
          </template>
        </chart-card>
      </a-col>
      <a-col :sm="24" :md="11" :xl="4" :offset='1' :style="{padding:0, marginBottom: '24px' }">
        <chart-card :loading="loading" title="待上账金额" total="￥126,560">
          <a-tooltip title="指标说明" slot="action">
            <a-icon type="info-circle-o" />
          </a-tooltip>
          <template slot="footer" style='text-align: right'>
            <trend flag="up" style="margin-right: 16px;">
              <span slot="term">周同比</span>
              12%
            </trend>
          </template>
        </chart-card>
      </a-col>

    </a-row>

    <a-row :gutter="24">
      <a-col :sm="24" :md="24" :xl="12">
        <a-card :loading="loading" :bordered="false" :body-style="{padding: '32px 32px 0 0 !important'}">
          <bar-multid title="活动举办场次大区分布图" :fields='fields' :dataSource="barData" :height='400'/>
          <div style='padding: 0 0 32px 32px'>
            <a-table
              ref="table"
              size="middle"
              bordered
              rowKey="type"
              :pagination='false'
              :columns="columns"
              :dataSource="barTableData"
            />
          </div>
        </a-card>
      </a-col>
      <a-col :sm="24" :md="24" :xl="12">
        <a-card :loading="loading" :bordered="false" :body-style="{padding: '32px 32px 0 0 !important'}">
          <bar-multid title="费用细类投放大区分布" :fields='fields' :dataSource="barData" :height='400'/>
          <div style='padding: 0 0 32px 32px'>
            <a-table
              ref="table"
              size="middle"
              bordered
              rowKey="type"
              :pagination='false'
              :columns="columns"
              :dataSource="barTableData"
            />
          </div>
        </a-card>
      </a-col>
    </a-row>
    <a-row :gutter="24" style='margin-top: 24px'>
      <a-col :sm="24" :md="24" :xl="24">
        <a-card :loading="loading" :bordered="false" :body-style="{padding: '32px 32px 0 0 !important'}">
          <line-chart-multid :dataSource="monthData" :fields='monthFields' :height='400' title="经销商预算增长趋势"/>
          <div style='padding: 0 0 32px 32px'>
            <a-table
              ref="table"
              size="middle"
              bordered
              rowKey="type"
              :pagination='false'
              :columns="columnss"
              :dataSource="monthTableData"
            />
          </div>
        </a-card>
      </a-col>
    </a-row>




  </div>
</template>

<script>

  import ChartCard from '@/components/ChartCard'
  import ACol from "ant-design-vue/es/grid/Col"
  import ATooltip from "ant-design-vue/es/tooltip/Tooltip"
  import MiniArea from '@/components/chart/MiniArea'
  import MiniBar from '@/components/chart/MiniBar'
  import MiniProgress from '@/components/chart/MiniProgress'
  import RankList from '@/components/chart/RankList'
  import Bar from '@/components/chart/Bar'
  import LineChartMultid from '@/components/chart/LineChartMultid'
  import HeadInfo from '@/components/tools/HeadInfo.vue'
  import BarMultid from '@/components/chart/BarMultid'
  import Trend from '@/components/Trend'
  import { getLoginfo,getVisitInfo } from '@/api/api'
  let columns= [
    {
      title: '行标题',
      align: 'left',
      dataIndex: 'type'
    },
    {
      title: '东北',
      align: 'left',
      dataIndex: '东北'
    },
    {
      title: '华东',
      align: 'left',
      dataIndex: '华东',
    },
    {
      title: '华中',
      align: 'left',
      dataIndex: '华中'
    },
    {
      title: '华北',
      align: 'left',
      dataIndex: '华北'
    },
    {
      title: '华南',
      align: 'left',
      dataIndex: '华南'
    },
    {
      title: '西北',
      align: 'left',
      dataIndex: '西北'
    },
    {
      title: '西南',
      align: 'left',
      dataIndex: '西南'
    },
    {
      title: '鲁皖赣',
      align: 'left',
      dataIndex: '鲁皖赣'
    }
  ]
  let columnss= [
    {
      title: '行类型',
      align: 'left',
      dataIndex: 'type'
    },
    {
      title: '一月',
      align: 'left',
      dataIndex: '1月'
    },
    {
      title: '二月',
      align: 'left',
      dataIndex: '2月'
    },
    {
      title: '三月',
      align: 'left',
      dataIndex: '3月',
    },
    {
      title: '四月',
      align: 'left',
      dataIndex: '4月'
    },
    {
      title: '五月',
      align: 'left',
      dataIndex: '5月'
    },
    {
      title: '六月',
      align: 'left',
      dataIndex: '6月'
    },
    {
      title: '七月',
      align: 'left',
      dataIndex: '7月'
    },
    {
      title: '八月',
      align: 'left',
      dataIndex: '8月'
    },
    {
      title: '九月',
      align: 'left',
      dataIndex: '9月'
    },
    {
      title: '十月',
      align: 'left',
      dataIndex: '10月'
    },
    {
      title: '十一月',
      align: 'left',
      dataIndex: '11月'
    },
    {
      title: '十二月',
      align: 'left',
      dataIndex: '12月'
    }
  ]
  const rankList = []
  for (let i = 0; i < 7; i++) {
    rankList.push({
      name: '白鹭岛 ' + (i+1) + ' 号店',
      total: 1234.56 - i * 100
    })
  }

  let fields=['广宣制作','人员','赠品自采','试吃','DM刊位']
  let barData = []
  for (let i = 1; i < columns.length; i += 1) {
    barData.push({
      type: columns[i].title,
      '广宣制作':Math.floor(Math.random() * 1000) + 200,
      '人员':Math.floor(Math.random() * 1000) + 200,
      '赠品自采':Math.floor(Math.random() * 1000) + 200,
      'DM刊位':Math.floor(Math.random() * 1000) + 200,
      '试吃':Math.floor(Math.random() * 1000) + 200,
    })
  }
  let barTableData=[]
  fields.map(v=>{
    let item={type:v}
    barData.forEach(bv=>{
        item[bv.type]=bv[v]
    })
    barTableData.push(item)
  })




  let monthFields=['东北','华东','华中','华北','华南','西北','西南','鲁皖赣']
  let monthData = []
  for (let i = 0; i < 12; i += 1) {
    monthData.push({
      type:`${i+1}月`,
      '东北':Math.floor(Math.random() * 1000) + 200,
      '华东':Math.floor(Math.random() * 1000) + 200,
      '华中':Math.floor(Math.random() * 1000) + 200,
      '华北':Math.floor(Math.random() * 1000) + 200,
      '华南':Math.floor(Math.random() * 1000) + 200,
      '西北':Math.floor(Math.random() * 1000) + 200,
      '西南':Math.floor(Math.random() * 1000) + 200,
      '鲁皖赣':Math.floor(Math.random() * 1000) + 200,
    })
  }
  let monthTableData=[]
  monthFields.map(v=>{
    let item={type:v}
    monthData.forEach(bv=>{
      item[bv.type]=bv[v]
    })
    monthTableData.push(item)
  })


  export default {
    name: "IndexChart",
    components: {
      ATooltip,
      ACol,
      ChartCard,
      MiniArea,
      MiniBar,
      MiniProgress,
      RankList,
      BarMultid,
      Bar,
      Trend,
      LineChartMultid,
      HeadInfo
    },


    data() {
      return {
        fields,
        monthFields,
        columns,
        columnss,
        barTableData,
        monthTableData,
        loading: true,
        center: null,
        rankList,
        monthData,
        barData,
        loginfo:{},
        visitFields:['ip','visit'],
        visitInfo:[],
        indicator: <a-icon type="loading" style="font-size: 24px" spin />
      }
    },
    created() {
      setTimeout(() => {
        this.loading = !this.loading
      }, 1000)
      // this.initLogInfo();
    },
    methods: {
      initLogInfo () {
        getLoginfo(null).then((res)=>{
          if(res.success){
            Object.keys(res.result).forEach(key=>{
              res.result[key] =res.result[key]+""
            })
            this.loginfo = res.result;
          }
        })
        getVisitInfo().then(res=>{
          if(res.success){
             this.visitInfo = res.result;
           }
         })
      },
    }
  }
</script>

<style lang="less" scoped>
  .circle-cust{
    position: relative;
    top: 28px;
    left: -100%;
  }
  .extra-wrapper {
    line-height: 55px;
    padding-right: 24px;

    .extra-item {
      display: inline-block;
      margin-right: 24px;

      a {
        margin-left: 24px;
      }
    }
  }

  /* 首页访问量统计 */
  .head-info {
    position: relative;
    text-align: left;
    padding: 0 32px 0 0;
    min-width: 125px;

    &.center {
      text-align: center;
      padding: 0 32px;
    }

    span {
      color: rgba(0, 0, 0, .45);
      display: inline-block;
      font-size: .95rem;
      line-height: 42px;
      margin-bottom: 4px;
    }
    p {
      line-height: 42px;
      margin: 0;
      a {
        font-weight: 600;
        font-size: 1rem;
      }
    }
  }
</style>
